<template>
  <div>
    <van-field v-model="msg"></van-field>
    <van-button @click="send">发送信息</van-button>
    <van-button @click="btnClick">关闭</van-button>
  </div>
</template>
<script>
import { io } from 'socket.io-client'
export default {
  data () {
    return {
      ws: '',
      msg: ''
    }
  },
  created () {
    // 连接
    this.ws = io('ws://119.91.150.211:1235')
    this.ws.addEventListener('connect', () => {
      console.log('连接成功')
    })
    // 接收 消息
    this.ws.addEventListener('message', data => {
      console.log(data)
    })
    // 监听是否关闭成功
    this.ws.addEventListener('disconnect', () => {
      console.log('关闭成功')
    })
  },
  methods: {
    send () {
      this.ws.emit('message', this.msg)
    },
    btnClick () {
      this.ws.close()
    }
  }
}
</script>
<style></style>
>
